#define _GNU_SOURCE
#include <stdlib.h>

#include <color.h>
#include <debug.h>
#include <unittest.h>

/**
 * DESC: Tests color MACROS
 *
 * IMP: HIGH
 */

int main( int argc, char *argv[] )
{
  color_t c1;
  color_t c2;
  COLOR_FROM_PAIR_ARGB( c1, 0x00, 0xab, 0xcd, 0xef );
  COLOR_FROM_ARGB( c2, 0x00abcdef );

  debug_level = 0; /* 1 = warn, 2 = info, 3 = verbose, 4 = debug mode */

  dbg( "c1.r = %x   c2.r = %x\n", c1.r, c2.r );
  dbg( "c1.g = %x   c2.g = %x\n", c1.g, c2.g );
  dbg( "c1.b = %x   c2.b = %x\n", c1.b, c2.b );
  dbg( "c1.a = %x   c2.a = %x\n", c1.a, c2.a );

  uint8_t a, b;

  a = c1.r; b = c2.r;
  assert_equal_hex8( a, b );
  a = c1.g; b = c2.g;
  assert_equal_hex8( a, b );
  a = c1.b; b = c2.b;
  assert_equal_hex8( a, b );
  a = c1.a; b = c2.a;
  assert_equal_hex8( a, b );

  dbg( "c1 = 0x%x c2 = 0x%x\n", COLOR_TO_ARGB( c1 ), COLOR_TO_ARGB( c2 ) );

  assert_equal_hex32( (uint32_t)COLOR_TO_ARGB( c1 ), (uint32_t)0x00abcdef );

  COLOR_FROM_PAIR_ARGB( c1, 0x11, 0x22, 0x33, 0x44 );
  assert_equal_hex32( (uint32_t)COLOR_TO_ARGB( c1 ), (uint32_t)0x11223344 );

  COLOR_FROM_PAIR_RGB( c1, 0xaa, 0xbb, 0xcc );
  assert_equal_hex32( (uint32_t)COLOR_TO_ARGB( c1 ), (uint32_t)0x11aabbcc );


  COLOR_FROM_PAIR_ARGB( c1, 0, 0, 0, 0 );
  assert_different_hex32( (uint32_t)COLOR_TO_ARGB( c1 ),
			  (uint32_t)COLOR_TO_ARGB( c2 ) );

  COLOR_COPY( c2, c1 );
  assert_equal_hex32( (uint32_t)COLOR_TO_ARGB( c1 ),
		      (uint32_t)COLOR_TO_ARGB( c2 ) );
  assert_equal_hex32( (uint32_t)COLOR_TO_ARGB( c1 ), (uint32_t)0x00abcdef );


  return 0;
}
